﻿package Naruto{
	import flash.display.Sprite;
	import flash.display.Stage;
//	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
//	import Naruto.Bloods.*;
//	import flash.events.MouseEvent;
//	import flash.events.KeyboardEvent;
//	import flash.ui.Keyboard;
	import flash.events.Event;
	
//	import flash.events.TimerEvent;
//	import flash.utils.Timer;
	
//	import flash.display.MovieClip; 	//导入影片剪辑类
	import Naruto.Frames.*;
	import Naruto.Music.*;
	import Naruto.Sound.*;
	
	public class Start extends Sprite{
		private var _stage:Stage;
		private var _Frame:Frame;			//场景基类
		
		private var _Frame0:Frame0;			//开始画面		
		private var _Frame1:Frame1;			//场景1
		private var _Frame2:Frame2;			//场景2
		private var _Frame3:Frame3;			//场景3
		private var _Frame4:Frame4;			//场景4
		private var _Frame5:Frame5;			//场景5
		private var _Frame6:Frame6;			//场景6 再不斩
		
		private var _Status:Status;			//人物状态
		private const _MUSICNUM:int = 2;	//加载音乐数量
		private const _SOUNDNUM:int = 1;	//加载声音数量
		private var _completeNum:int = 0;	//事件加载完成数目
		
		private var _music1:PlayMusic;		//背景音乐1
		private var _music2:PlayMusic;	
		
		public var _sound1:PlaySound;		//飞镖音效
		
		public function Start(){			
			this._stage = stage;
			this._stage.scaleMode = StageScaleMode.NO_SCALE;

			this._music1 = new PlayMusic(1);	//num=1
			this._music2 = new PlayMusic(2);	//   =2
			
			this._music1.addMusicLoadCompleteListener(this.musicLoadComplete);
			this._music2.addMusicLoadCompleteListener(this.musicLoadComplete);
			
			
		}
		
		public function musicLoadComplete(e : Event) {
			this._completeNum++;
			
			if (this._completeNum == _MUSICNUM) {
				this._sound1 = new PlaySound(1);
				this._sound1.addSoundLoadCompleteListener(this.soundLoadComplete);
			}
		}
		public function soundLoadComplete(e : Event) {
			this._completeNum++;
			
			if ( this._completeNum >= _MUSICNUM + _SOUNDNUM ) {
				this.init();
			}
		}
		
		public function init(){	//开始游戏
			this._Status = new Status();
			this._Frame0 = new Frame0(this._Status, this._stage, this);
			
			//this._music0.Play();
		}
		
		public function _changeFrame(aframe:Number){	//负责切换舞台
			switch(aframe){
				case -1:{
						 this._music1.Stop();
						 this._music2.Stop();
						 this._Frame0 = new Frame0(this._Status, this._stage, this);break;}
				case 0:{ this._Frame0 = null;
						 this._music1.Stop();//任务失败重玩时
						 this._music2.Stop();//任务失败重玩时						 
						 this._music1.Play();
						 this._Frame1 = new Frame1(this._Status, this._stage, this);break;}	
				case 1:{ this._Frame1 = null;
					     this._Frame2 = new Frame2(this._Status, this._stage, this);break;}	//切换到第二幕
				case 2:{ this._Frame2 = null;
						 this._Frame3 = new Frame3(this._Status, this._stage, this);break;}
				case 3:{ this._Frame3 = null;
						 this._Frame4 = new Frame4(this._Status, this._stage, this);break;}
				case 4:{ this._Frame4 = null;
						 this._Frame5 = new Frame5(this._Status, this._stage, this);break;}
				case 5:{ this._Frame5 = null;
						 this._music1.Stop();
						 this._music2.Play();
						 this._Frame6 = new Frame6(this._Status, this._stage, this);break;}
				case 6:{	//重玩 ，返回第一帧
						this._Frame6 = null;
						this._music2.Stop();
						this._music1.Play();
						this._Frame1 = new Frame1(this._Status, this._stage, this);break;
						}
				default:return;
			}
		}
	}
}